<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of login
 *
 * @author pudy
 */
class Register extends CI_Controller {

    function index() {
        $data['title'] = 'Registration Page';
        $data['main_content'] = 'register/register_view';
        $fl = $this->session->flashdata('message');
        if ($fl != '')
            $data['message'] = $fl;

        $this->load->view('includes/template', $data);
    }

    function submit() {
        $name = $this->input->post('name');
        $email = $this->input->post('email');
        $username = $this->input->post('username');
        $password = $this->input->post('password');
        //$password = md5($this->input->post('password'));

        if ($name == NULL || $email == NULL || $username == NULL || $password == NULL) {
            $message = 'Wrong input.';
            $this->session->set_flashdata('message', $message);
            redirect('/register', 'refresh');
        } else {
            $options = array(
                'username' => $username,
                'password' => $password,
                'name' => $name,
                'email' => $email
            );
            $this->load->model('userModel', 'userModel');
            $getReturnInsert = $this->userModel->addUser($options);

            $message = 'Registration success. Please login.';
            $this->session->set_flashdata('message', $message);
            redirect('/welcome', 'refresh');
        }
    }

}

?>
